package com.SparkCore.ACC

import org.apache.spark.{SparkConf, SparkContext}

import scala.collection.mutable

/**
 * 广播变量
 */
object Spark05_Bc {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local").setAppName("BC")
    val sc = new SparkContext(sparkConf)

    val rdd1 = sc.makeRDD(List(
      ("a", 1), ("b", 2), ("c", 3)
    ))
    val map = mutable.Map(("a", 4), ("b", 5), ("c", 6))

//    val rdd2 = sc.makeRDD(List(
//     ("a", 4), ("b", 5), ("c", 6)
//    ))

    //join 会导致数据量几何增长，会导致影响shuffle的性能，不推荐使用
    //val joinRDD = rdd1.join(rdd2)
    //joinRDD.collect().foreach(println)

    rdd1.map{
      case (w , c) => {
        val l = map.getOrElse(w, 0)
        (w , (c,l))
      }
    }.collect().foreach(println)


    sc.stop()
  }
}
